//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.andromeda.androbench2;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import java.util.ArrayList;
import java.util.Collections;

public class History extends CustomActivity {
    private History.GroupAdapter adapter;
    private ArrayList<HistoryData> al_History;
    ImageButton btnClearHistory;
    SQLiteDatabase db;
    private HistoryDB historyDBHelper;
    private ListView listview;
    TextView tv_history_message;
    TextView tv_recent_benchmarking;

    public History() {
    }

    void ItemClick(AdapterView<?> var1, View var2, int var3, long var4) {
        Builder var6 = new Builder(this);
        var6.setMessage(((HistoryData)this.al_History.get(var3)).getResult()).setCancelable(false).setPositiveButton("Ok", new OnClickListener() {
            public void onClick(DialogInterface var1, int var2) {
            }
        });
        AlertDialog var8 = var6.create();
        var8.setTitle("History");
        var8.setIcon(R.drawable.icon_history);
        var8.show();
        CustomActivity.setGlobalFont((ViewGroup)var8.getWindow().getDecorView());
    }

    public void onCreate(Bundle var1) {
        super.onCreate(var1);
        this.setRequestedOrientation(1);
        this.setContentView(R.layout.history);
        this.listview = (ListView)this.findViewById(R.id.HistoryListView);
        this.al_History = new ArrayList();
        this.tv_history_message = (TextView)this.findViewById(R.id.HistoryMessage);
        this.tv_recent_benchmarking = (TextView)this.findViewById(R.id.RecentBenchmarking);
        this.listview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> var1, View var2, int var3, long var4) {
                History.this.ItemClick(var1, var2, var3, var4);
            }
        });
        this.historyDBHelper = new HistoryDB(this, (String)null, (CursorFactory)null);
        this.db = this.historyDBHelper.getReadableDatabase();
        this.btnClearHistory = (ImageButton)this.findViewById(R.id.btnClearHistory);
        this.btnClearHistory.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View var1) {
                History.this.db.delete("history", (String)null, (String[])null);
                History.this.db.execSQL("DELETE FROM history;");
                History.this.al_History.clear();
                History.this.listview.setAdapter(History.this.adapter);
                History.this.tv_recent_benchmarking.setText("Recent benchmarking\n(No history)");
                History.this.tv_history_message.setText("You have no benchmark history");
            }
        });
    }

    public void onDestroy() {
        super.onDestroy();
        this.historyDBHelper.close();
    }

    public void onResume() {
        super.onResume();
        String var1 = null;
        Cursor var2 = this.db.query("history", new String[]{"date", "target", "filesize_read", "filesize_write", "buffersize_seq", "buffersize_rnd", "use_buffer", "avg_mbps_sr", "avg_mbps_sw", "avg_mbps_rr", "avg_iops_rr", "avg_mbps_rw", "avg_iops_rw", "avg_perf_sqlite_insert", "avg_perf_sqlite_update", "avg_perf_sqlite_delete", "one_filesize", "num_thread", "transaction_size", "journal_mode", "index_usage"}, (String)null, (String[])null, (String)null, (String)null, (String)null);
        this.al_History.clear();

        while(var2.moveToNext()) {
            var1 = var2.getString(0);
            this.al_History.add(new HistoryData(var2.getString(0), var2.getString(1), var2.getInt(2), var2.getInt(3), var2.getInt(4), var2.getInt(5), var2.getString(6), var2.getDouble(7), var2.getDouble(8), var2.getDouble(9), var2.getDouble(10), var2.getDouble(11), var2.getDouble(12), var2.getDouble(13), var2.getDouble(14), var2.getDouble(15), var2.getInt(16), var2.getInt(17), var2.getInt(18), var2.getString(19), var2.getInt(20)));
        }

        Collections.reverse(this.al_History);
        if (var2.getCount() != 0) {
            this.tv_recent_benchmarking.setText("Recent benchmarking\n" + var1);
        }

        var2.close();
        if (this.al_History.size() > 0) {
            this.tv_history_message.setText("");
            this.adapter = new History.GroupAdapter(this, R.layout.row_history, this.al_History);
            this.listview.setAdapter(this.adapter);
        } else {
            this.tv_history_message.setText("You have no benchmark history");
        }
    }

    public class GroupAdapter extends ArrayAdapter<Object> {
        private ArrayList<HistoryData> item;
        private HistoryData temp;

        public GroupAdapter(Context var2, int var3, ArrayList var4) {
            super(var2, var3, var4);
            this.item = var4;
        }

        public View getView(int var1, View var2, ViewGroup var3) {
            View var4 = var2;
            this.temp = (HistoryData)this.item.get(var1);
            if (var2 == null) {
                var4 = ((LayoutInflater)History.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.row_history, (ViewGroup)null);
            }

            if (this.temp != null) {
                TextView var5 = (TextView)var4.findViewById(R.id.row_history_date);
                var5.setText(this.temp.getDate());
                var5.setTypeface(Typeface.createFromAsset(History.this.getApplicationContext().getAssets(), "fonts/PT_Sans-Web-Regular.ttf"));
            }

            return var4;
        }
    }
}
